package br.com.mmm.javacenter.framework.view.menu;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import br.com.mmm.javacenter.framework.annotations.Controller;
import br.com.mmm.javacenter.framework.configuration.IocController;
import br.com.mmm.javacenter.framework.entity.EntidadeBase;
import br.com.mmm.javacenter.framework.util.Atributo;
import br.com.mmm.javacenter.framework.view.ContextAttributes;
import br.com.mmm.javacenter.framework.view.servlet.ServletFacade;

@Controller("menu")
public class MenuController {
	public void cadastros(ServletFacade sf){
		List<Class<? extends EntidadeBase<?>>> entityBeans = IocController.entityBeans;
		MenuLateral menu = new MenuLateral();
		for(Class<? extends EntidadeBase<?>> entity:entityBeans){
			menu.addMenuItems(new MenuLateralItem(sf.getServerPath("generic", "lista",new Atributo("class",entity.getName())), entity.getSimpleName()));
		}
		Collections.sort(menu.getMenuItems(),new Comparator<MenuLateralItem>() {
			public int compare(MenuLateralItem o1, MenuLateralItem o2) {
				return o1.getDescricao().compareTo(o2.getDescricao());
			}
		});
		sf.setMenuLateral(menu);
	}
}
